<template>
  <div>
    <Spin fix size="large">
      <Icon type="ios-loading" size="198" class="demo-spin-icon-load"></Icon>
      <div>登陆中...</div>
    </Spin>
  </div>
</template>

<script>
import Qs from "qs";
import { Message, Spin, Icon } from "view-design";
import config from "@/utils/config";
import appService from "@/utils/appService";
export default {
  components: {
    Spin,
    Icon
  },
  async mounted() {
    let windowQuery = window.location.search;
    let query = Qs.parse(windowQuery, { ignoreQueryPrefix: true });
    if (query.code) {
      let response = await appService.getRequest(
        `${config.serverProxy}${config.authServicePath}/callback`,
        query
      );
      if (response.status === 200 && response.data.errorCode === 0) {
        appService.saveUserInfo(response.data.data);
      }
      this.$router.push("/");
    } else {
      Message.error("无效授权码,3秒后跳转到登录页");
      window.setTimeout(() => {
        this.$router.push("/signin");
      }, 3000);
    }
  }
};
</script>

<style>
.demo-spin-icon-load {
  animation: ani-demo-spin 1s linear infinite;
}
@keyframes ani-demo-spin {
  from {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(180deg);
  }
  to {
    transform: rotate(360deg);
  }
}
.demo-spin-col {
  height: 100px;
  position: relative;
  border: 1px solid #eee;
}
</style>